<extend name="Public/base" />
<block name="body">
    <form action="{:U('Relation/export')}" method="POST" id="form1" onkeydown="if(event.keyCode==13)return false;" class="row" style="margin-left: 0px;margin-top:5px;">
        <div class="cf">
            <button   class="btn btn-warning" >导出</button>
            <div class="search-form fr cf">
                <div class="sleft">
                    <input type="text" name="realname" class="search-input" value="{:I('realname')}"  placeholder="客户查询" style="height: 35px;width:100px;margin-left: 5px;">
                    <input type="text" name="shop" class="search-input" value="{:I('shop')}"  placeholder="店铺名查询" style="height: 35px;width:100px;margin-left: 5px;">
                    <input type="text" name="street" class="search-input" value="{:I('street')}"  placeholder="街道地址查询" style="height: 35px;width:100px;margin-left: 5px;">
                    <input type="text" name="user_phone" class="search-input" value="{:I('user_phone')}"  placeholder="手机号查询" style="height: 35px;width:100px;margin-left:5px;">
                    <input type="text" name="saler" class="search-input" value="{:I('saler')}"  placeholder="业务员查询" style="height: 35px;width:100px;margin-left:5px;">
                    <a class="sch-btn btn btn-success" href="javascript:;" id="search" url="{:U('index')}">搜索</a>
                </div>
            </div>
        </div>
        <div class="data-table table-striped">
            <table class="table table-hover">
                <thead class="" style="color:#FFF;">
                    <tr>
                        <th class="" style="background: #353535;line-height: 40px;">编  号</th>
                        <th class="" style="background: #353535;line-height: 40px;">客  户</th>
                        <th class="" style="background: #353535;line-height: 40px;">余  额</th>
                        <th class="" style="background: #353535;line-height: 40px;">手机号</th>
                        <th class="" style="background: #353535;line-height: 40px;">店  名</th>
                        <th class="" style="background: #353535;line-height: 40px;">业务员</th>
                        <th class="" style="background: #353535;line-height: 40px;">地  址</th>
                        <th class="" style="background: #353535;line-height: 40px;">操  作</th>
                    </tr>
                </thead>
                <tbody>
                <volist name="buyers" id="buyer">
                    <tr class="" style="margin-top: 3px;background: none;border: none;">
                        <td class="" data-id="{$buyer.id}" style="border: 1px solid #30333F;font-weight: 700;">{$buyer.id}</td>
                        <td class="" data-name="{$buyer.realName}" style="border: 1px solid #30333F;">{$buyer.realName}</td>
                        <td class="" style="border: 1px solid #30333F;">{$buyer.amount}</td>
                        <td class="" style="border: 1px solid #30333F;">{$buyer.phone}</td>
                        <td class="" style="border: 1px solid #30333F;">{$buyer.shopName}</td>
                        <td class="" style="border: 1px solid #30333F;">{$buyer.sname}</td>
                        <td class="" style="border: 1px solid #30333F;max-width: 180px;">{$buyer.city}{$buyer.area}{$buyer.street}</td>
                        <td class="" style="border: 1px solid #30333F;">
                            <a href="{:U('Relation/details')}&uid={$buyer['id']}" class="btn btn-default">明细</a>
                            <a href="{:U('Relation/amountFlow2')}&uid={$buyer['id']}&nickname={$buyer['realName']}" class="btn btn-default">余额明细</a>

                        </td>
                    </tr>
                </volist>
                </tbody>
            </table>
        </div>
        <div class="page">
            {$_page}
        </div>
    </form>
</block>
<block name="script">
    <script>
        $("#search").click(function () {
            var url = $(this).attr('url');

            var query = $('.search-form').find('input').serialize();
            var queryselect = $('.search-form').find('select').serialize();

            query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g, '');
            query = query.replace(/^&/g, '');
            queryselect = queryselect.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g, '');
            queryselect = queryselect.replace(/^&/g, '');

            if (url.indexOf('?') > 0) {
                url += '&' + query;
                url += '&' + queryselect;
            } else {
                url += '?' + query;
                url += '?' + queryselect;
            }

            window.location.href = url;
        });
        //回车搜索
        $(".search-input").keyup(function (e) {
            if (e.keyCode === 13) {
                $("#search").click();
                return false;
            }
        });
        $("#states").select2({
            placeholder: "请选择商品"
        });

        var $eventSelect = $("#states");
        var flag = $("#flag");
        var $pid = $(".pid");
        //商品是否已加入活动flag------数组
        var goodsId=[];
        //将数据库活动商品加入flag
        $pid.each(function(){
            var $this = $(this);
            goodsId.push(String($this.data('pid')));
        });
        $eventSelect.on("change", function (e) {
             //判断新加商品是否已在flag中，>-1为存在
            if(goodsId.indexOf($eventSelect.val())>-1){
                return false;
            }else{
                goodsId.push($eventSelect.val());
                flag.before(
                        '<div class="col-md-12"  id="'+$eventSelect.val()+'" style="line-height:50px;margin-top: 3px;">'+
                        '<input type="text" readonly style="border:1px solid #428BCA;" class="col-md-1 pid" data-pid="'+$eventSelect.val()+'"  name="pid[]"   value="'+$eventSelect.val()+'" >' +
                        '<input type="text" readonly style="border:1px solid #428BCA;" class="col-md-3 " name="pname[]" value="'+$("#states  option:selected").text()+'" >' +
                        '<input type="text" readonly style="border:1px solid #428BCA;" class="col-md-1"  name="price[]" value="'+$("#states  option:selected").data('price')+'">' +
                        '<input type="text" style="border:1px solid #428BCA;" class="col-md-1" name="price1[]">'+
                        '<input type="text" style="border:1px solid #428BCA;" class="col-md-1"  name="num1[]">'+
                        '<span class="col-md-1" style="border: 1px solid #30333F;font-weight: 700;" onclick="deleteThis('+$eventSelect.val()+')"><a  class="btn btn-default ajax-get confirm" style="background:#F0AD4E;color:#FFF;font-weight: 700;">删除</a></span>' +
                        '<span class="col-md-4"></span>' +
                        ' </div>');
            }
        }
        );
        $("#submitForm").click(function(){
            $("#form1").submit();
        });
        function deleteThis(id){
            id=String(id);
            goodsId.splice(goodsId.indexOf(id),1);
            $("#"+id).remove();
        };
    </script>
</block>
